package com.wlyuan.index.domain.index.valueobj;

import com.wlyuan.index.domain.index.CombineIndex;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
 * @author yuanjie
 */
@Data
@Slf4j
@Deprecated
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CombineRelation extends Relation {
    private boolean callQuote(CombineIndex index) {
        return CombineStatus.canQuote(this.getStatus())
                && index.canQuote()
                && Quotation.canQuote(this.getQuotationStatus());
    }

    public void buildQuotation(CombineIndex index) {
        this.quotation().map(quotation -> {
            this.setQuotationId(quotation.getQuotationId());
            this.setQuotationNo(quotation.getQuotationNo());
            this.setQuotationStatus(quotation.getStatus());
            return quotation;
        });

        // 已关闭合单/已过关账期 -> 报价: 已关闭
        if (Quotation.endQuote(this, index)) {
            this.closeQuote();
        }

        this.setCallQuote(this.callQuote(index));
    }
}